package com.wangsh.userscenter.users.service.impl;

import java.util.UUID;

import org.springframework.stereotype.Service;

import com.wangsh.userscenter.common.service.BaseServiceImpl;
import com.wangsh.userscenter.common.util.ConstatFinalUtil;
import com.wangsh.userscenter.users.pojo.AAdmins;
import com.wangsh.userscenter.users.pojo.AUsers;
import com.wangsh.userscenter.users.service.IUsersOperService;

/**
 * 用户Service的实现类
 *  
 * @author WangshSxt
 *
 */
@Service("usersOperService")
public class UsersOperServiceImpl extends BaseServiceImpl implements IUsersOperService
{
	@Override
	public boolean addUsersTokenService(AUsers users)
	{
		String token = users.getTokenStr() ; 
		if(token == null || "".equalsIgnoreCase(users.getTokenStr()))
		{
			token = UUID.randomUUID().toString() ; 
			users.setTokenStr(token);
		}
		/* 将token添加到redis中 */
		String key = "users_token_" + users.getTokenStr() ; 
		return this.redisUtil.put(key, users.toJSON().toJSONString(), Integer.valueOf(ConstatFinalUtil.CONFIG_JSON.getString("timeout.token")));
	}

	@Override
	public boolean addAdminsTokenService(AAdmins admins)
	{
		String token = admins.getTokenStr() ; 
		if(token == null || "".equalsIgnoreCase(admins.getTokenStr()))
		{
			token = UUID.randomUUID().toString() ; 
			admins.setTokenStr(token);
		}
		/* 将token添加到redis中 */
		String key = "admins_token_" + admins.getTokenStr() ; 
		return this.redisUtil.put(key, admins.toJSON().toJSONString(), Integer.valueOf(ConstatFinalUtil.CONFIG_JSON.getString("timeout.token")));
	}

	@Override
	public boolean removeUsersTokenService(AUsers users)
	{
		String token = users.getTokenStr() ; 
		/* 将token添加到redis中 */
		String key = "users_token_" + token ; 
		return this.redisUtil.delete(key);
	}

	@Override
	public boolean removeAdminsTokenService(AAdmins admins)
	{
		String token = admins.getTokenStr() ; 
		/* 将token添加到redis中 */
		String key = "admins_token_" + token ; 
		return this.redisUtil.delete(key);
	}
}
